package com.itheima.service.impl;

import cn.hutool.core.lang.Snowflake;
import com.itheima.domain.Category;
import com.itheima.mapper.CategoryMapper;
import com.itheima.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * date: 2022/5/12 21:05
 *
 * @author daya000
 */
@Service
public class CategeryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper mapper;

    @Override
    public Boolean addCategory(Category category) {
        long id = new Snowflake().nextId();
        category.setId(Long.toString(id));
        category.setCreateTime(new Date());
        category.setUpdateTime(new Date());
        category.setCreateUser("1");
        category.setUpdateUser("1");

        return mapper.addCategory(category)>0;
    }

    @Override
    public Category selectByname(String name) {
        return mapper.selectByName(name);
    }

    @Override
    public Boolean updateCategory(Category category) {
        category.setUpdateTime(new Date());
        category.setUpdateUser("1");
        return mapper.updateCategory(category)>0;
    }

    @Override
    public Boolean deleteById(String id) {
        return mapper.deleteById(id)>0;
    }

    @Override
    public List<Category> selectByPage(Integer page, Integer pageSize) {
        Integer index=(page-1)*pageSize;
        return mapper.selectByPage(index,pageSize);
    }

    @Override
    public Long selectTotal(String name) {
        return mapper.selectTotal(name);
    }

    @Override
    public List<Category> selectList() {
        List<Category> categoryList = mapper.selectList();
        return categoryList;
    }


}
